<script setup>
import { ref, onMounted } from 'vue'
import { useRoute } from 'vue-router'

const route = useRoute()
const complaint = ref(null)

onMounted(() => {
  const stored = localStorage.getItem('complaints')
  if (stored) {
    const list = JSON.parse(stored)
    complaint.value = list.find(item => String(item.id) === String(route.params.id))
  }
  if (!complaint.value) {
    complaint.value = {
      title: '未找到该投诉',
      content: '',
      date: '',
      status: '',
      result: '',
      attachment: { name: '', url: '' }
    }
  }
})
</script>

<template>
  <div class="complaint-detail-bg">
    <div class="complaint-container">
      <div class="complaint-breadcrumb">首页 / 违规投诉 / <span class="black">投诉详情</span></div>
      <div class="complaint-detail-card">
        <div class="complaint-title">{{ complaint.title }}</div>
        <div class="complaint-meta">
          <span>创建时间：{{ complaint.date }}</span>
          <span class="meta-status">处理状态：<span :class="complaint.status === '正在处理中' ? 'status-processing' : 'status-done'">{{ complaint.status }}</span></span>
        </div>
        <div class="complaint-section">
          <div class="section-label">投诉信息：</div>
          <div class="section-value">{{ complaint.content }}</div>
        </div>
        <div v-if="complaint.attachment && complaint.attachment.name" class="complaint-attach">
          <span class="attach-icon"><img src="/images/公告列表详情页/u251.png" alt="附件图标" style="width:22px;height:22px;display:block;margin:auto;" /></span>
          <span>附件：</span>
          <a :href="complaint.attachment.url" download class="attach-text">{{ complaint.attachment.name }}</a>
        </div>
        <div class="complaint-section">
          <div class="section-label">处理结果：</div>
          <div class="section-value">{{ complaint.result || '暂无' }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped>
.complaint-detail-bg {
  background: #fafbfc;
  min-height: 100vh;
  padding-bottom: 40px;
}
.complaint-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 40px;
}
.complaint-breadcrumb {
  font-size: 15px;
  color: #888;
  margin: 24px 0 0 0;
  text-align: left;
}
.complaint-breadcrumb .black {
  color: #222;
  font-weight: normal;
}
.complaint-detail-card {
  background: #fff;
  border-radius: 12px;
  margin: 24px 0 0 0;
  padding: 32px 40px 24px 40px;
  box-shadow: 0 2px 8px #e0f7fa55;
}
.complaint-title {
  font-size: 26px;
  font-weight: bold;
  margin-bottom: 18px;
  text-align: left;
  color: #222;
}
.complaint-meta {
  color: #888;
  font-size: 15px;
  margin-bottom: 32px;
  display: flex;
  gap: 32px;
  text-align: left;
  justify-content: flex-start;
}
.meta-status {
  color: #888;
}
.status-processing {
  color: #ff9800;
  font-weight: bold;
}
.status-done {
  color: #4caf50;
  font-weight: bold;
}
.complaint-section {
  display: flex;
  margin-bottom: 18px;
}
.section-label {
  width: 90px;
  color: #888;
  font-size: 15px;
  flex-shrink: 0;
}
.section-value {
  color: #333;
  font-size: 16px;
  line-height: 1.8;
  flex: 1;
}
.complaint-attach {
  color: #888;
  font-size: 15px;
  display: flex;
  align-items: center;
  margin-bottom: 18px;
  text-align: left;
}
.attach-icon {
  font-size: 18px;
  margin-right: 6px;
}
.attach-text {
  color: #1abc9c;
  margin-left: 4px;
  text-decoration: underline;
  cursor: pointer;
}
</style> 